//
//  bcDiscriminatorAppController.m
//  bcDiscriminatorApplicationController
//
//  Created by Volker Runkel on 03.11.06.
//  Copyright 2006 Volker Runkel, ecoObs.
//	Mail me at runkel @ eco obs . de
//
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
*/

#import <Cocoa/Cocoa.h>
#import <BCREWrapper.h>

@interface bcDiscriminatorAppController : NSObject
{
	IBOutlet NSButton		*chooseFilesButton;
	IBOutlet NSButton		*startPredButton;
	IBOutlet NSButton		*cancelButton;
	
	IBOutlet NSProgressIndicator *progressBar;
    
	IBOutlet NSTextView		*consoleView;
	IBOutlet NSTextField	*rversion;
	
	IBOutlet NSTextField	*inputFile;
	IBOutlet NSButton		*omitResFiles;
	
	IBOutlet NSTreeController *resultsTreeController;
	IBOutlet NSOutlineView	*resultsOutlineView;
	NSPersistentStoreCoordinator *persistentStoreCoordinator;
    NSManagedObjectModel *managedObjectModel;
    NSManagedObjectContext *managedObjectContext;
	
	BOOL inputAvailable;
	BOOL manualPrediction;
	BOOL newFile;
	BOOL canceled;
	
	NSString				*discObject;
	NSString				*outlObject;
	float					outlObjectProb;

	NSMutableArray			*probsArray;
	NSMutableArray			*classArray;
	NSMutableArray			*lastCallNumbers; // needed to walk through results
	NSMutableArray			*results; // interim storage for result species
	NSMutableArray			*resultProbs; // interim storage for result probabilities
	NSDictionary			*availableDiscrObjects;	// need filling at app start!
	NSDictionary			*availableOutlierObjects;	// need filling at app start!
	NSDictionary			*availableOutlierProbs;	// need filling at app start!
	NSMutableArray			*toDoList; // gets filled onc at pred start and then whenever necessary
	
	NSMutableDictionary		*stepAM;	// holds average and max per analysis step
	NSString				*maxClass;
	NSString				*lastClass;
	float					lastAvg;
	
	NSMutableArray			*winList;
	NSMutableArray			*seconds;
	NSMutableArray			*candidates;
	
	NSMutableArray			*outputResults;
	
	BOOL firstResultEntry;
	BOOL tooFewCalls;
	BOOL checking;
	
	int	mainGenusLevel;
	
	float minProb;
	float minCalls;
	
	IBOutlet NSArrayController	*resultController;
	IBOutlet NSView				*fileChooseAccView;
	IBOutlet NSButton			*deepTraverse;

}

- (NSPersistentStoreCoordinator *) persistentStoreCoordinator;

- (NSArray*)discrObjects;
- (NSArray*)outlObjects;

- (void)writeToConsole:(NSString*)text;
- (void)setRVersion:(NSString*)text;

- (NSArray*)buildFilesFromDeepTraversal:(NSString*)startFolder;
- (IBAction)chooseInputFile:(id)sender;
- (IBAction)startPrediction:(id)sender;
- (IBAction)cancelPrediction:(id)sender;

- (void)setProbsArray:(NSMutableArray*)newArray;
- (void)setClassArray:(NSMutableArray*)newArray;

- (NSString*)currentAnalyseLevel;
- (NSString*)currentOutlierLevel;
- (float)currentOutlObjectProb;

- (void)updateResultsTable;

- (float)currRowMax:(int)currRow withCols:(int)cols andRows:(int)rows;
- (int)currRowClass:(int)currRow withCols:(int)cols andRows:(int)rows;
- (void)evaluateAutomaticPrediction;
- (void)checkToDo;
- (NSArray*)updateOutputResultsWithOutlierData:(NSArray*)outlResults forCalls:(NSArray*)callList;

- (void)evalOutputResults;
- (BOOL)getResultsFromTree;
- (void)walkTheTree:(NSIndexPath*)startHere;
- (void)extractSpecies:(BOOL)evalResults;

- (IBAction)deepTraversalChange:(id)sender;

@end
